#include <iostream>
#include <cctype>

using namespace std;

bool isPalindrome(string s) {
    int left = 0;
    int right = s.length() - 1;
    
    while (left < right) {
        while (left < right && !isalnum(s[left])) {
            left++;
        }
        while (left < right && !isalnum(s[right])) {
            right--;
        }
        
        if (tolower(s[left]) != tolower(s[right])) {
            return false;
        }
        
        left++;
        right--;
    }
    
    return true;
}

int main() {
    string s1 = "A man, a plan, a canal: Panama";
    string s2 = "race a car";
    string s3 = "Was it a car or a cat I saw?";
    string s4 = "No 'x' in Nixon";
    
    cout << s1 << " is " << (isPalindrome(s1) ? "a palindrome" : "not a palindrome") << endl;
    cout << s2 << " is " << (isPalindrome(s2) ? "a palindrome" : "not a palindrome") << endl;
    cout << s3 << " is " << (isPalindrome(s3) ? "a palindrome" : "not a palindrome") << endl;
    cout << s4 << " is " << (isPalindrome(s4) ? "a palindrome" : "not a palindrome") << endl;
    
    return 0;
}
